﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Resources;
using YasharEl.Infrastructure.ResourcesManagement.Configuration;

namespace YasharEl.Infrastructure.ResourcesManagement.Managers.Database
{
    /// <summary>
    /// Custom resource set for creating sets of resources from a database
    /// </summary>
    [SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
    public class DataResourceSet : CommonResourceSet
    {
        #region Fields

        private string baseName;
        private DataProvider dataProvider;
        private string connectionString;
        private CultureInfo cultureInfo;

        #endregion

        #region Construction
        /// <summary>
        /// Initializes a new instance of the <see cref="DataResourceSet"/> class.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <param name="baseName">the base name of the set of resources.</param>
        /// <param name="cultureInfo">The culture.</param>
        public DataResourceSet(DataProvider dataProvider, string connectionString, string baseName, CultureInfo cultureInfo)
            : base(new DataResourceReader(dataProvider, connectionString, baseName, cultureInfo))
        {
            this.dataProvider = dataProvider;
            this.connectionString = connectionString;
            this.baseName = baseName;
            this.cultureInfo = cultureInfo;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Returns the preferred resource reader class for this kind of <see cref="T:System.Resources.ResourceSet"></see>.
        /// </summary>
        /// <returns>
        /// Returns the <see cref="T:System.Type"></see> for the preferred resource reader for this kind of <see cref="T:System.Resources.ResourceSet"></see>.
        /// </returns>
        public override Type GetDefaultReader()
        {
            return typeof(DataResourceReader);
        }

        /// <summary>
        /// Returns the preferred resource writer class for this kind of <see cref="T:System.Resources.ResourceSet"></see>.
        /// </summary>
        /// <returns>
        /// Returns the <see cref="T:System.Type"></see> for the preferred resource writer for this kind of <see cref="T:System.Resources.ResourceSet"></see>.
        /// </returns>
        public override Type GetDefaultWriter()
        {
            return typeof(DataResourceWriter);
        }

        /// <summary>
        /// Creates the default resource reader.
        /// </summary>
        /// <returns>IResourceReader instance</returns>
        public override IResourceReader CreateDefaultReader()
        {
            return new DataResourceReader(dataProvider, connectionString, baseName, cultureInfo);
        }

        /// <summary>
        /// Creates the default resource writer.
        /// </summary>
        /// <returns>IResourceWriter instance</returns>
        public override IResourceWriter CreateDefaultWriter()
        {
            return new DataResourceWriter(baseName, cultureInfo);
        }
        #endregion
    }
}
